package com.lintcode.solution;

public class Solution_31 {
    public static void main(String[] agrs) {
        Solution_31 solution = new Solution_31();
        int[] nums = { 1, 2, 2, 3, 4, 5, 1 };
        System.out.println(solution.partitionArray(nums, 2));
    }
    
    public int partitionArray(int[] nums, int k) {
        int result = 0;
        if (nums == null || nums.length == 0) {
            return result;
        }
        int i = 0, j = nums.length - 1, temp;
        while (true) {
            if (nums[ i ] < k) {
                temp = nums[ j ];
                nums[ j ] = nums[ i ];
                nums[ i ] = temp;
                result++;
                j--;
            } else {
                i++;
            }
            if (i > j) {
                break;
            }
        }
        for (int num : nums) {
            System.out.println(num);
        }
        return result;
    }
}
